package com.sky.mapper;

import com.sky.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;

//启动类上面有注解了，这里就不用加@Mapper
public interface UserMapper {

    //根据opendi查询用户
    @Select("select * from user where openid =#{openid}")
    User getByOpenid(String openid);


    //新增用户
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into user values (null,#{openid},#{name},#{phone},#{sex},#{idNumber},#{avatar},#{createTime})")
    void insert(User user);

    //根据用户主键查询用户信息
    @Select("select * from user where id=#{id}")
    User getById(Long id);

    /**
     * 根据创建时间统计用户数量
     * @param endTime
     * @return
     */
    // @Select("select count(*) from user where create_time <= #{endTime}")
    Integer countBy(LocalDateTime beginTime,LocalDateTime endTime);

    // @Select("select count(*) from user where create_time <= #{endTime} and create_time >=#{beginTime}")
    // Integer countBy2(LocalDateTime beginTime,LocalDateTime endTime);
    //使用xml定义一个通用的统计用户数量方法，代替上面2个语句。
}
